﻿Imports System.IO
Imports System.Windows.Forms
Imports GrapeCity.ActiveReports.Export.Pdf.Page
''' <summary>
''' 2019.11.19
''' 报表类型
''' </summary>
Public Enum MReportType
    excel = 1
    PDF = 3
    Word = 2
End Enum
Public Class MyReport

#Region "类申明变量"

    ''' <summary>
    ''' 说明：数据库链接参数      
    ''' </summary>
    ''' <remarks></remarks>
    Private _nConnection1 As String

    ''' <summary>
    ''' 说明：字段对应模块名=f_columnlib.col_tablename      
    ''' </summary>
    ''' <remarks></remarks>
    Private _nColumnName As String

    ''' <summary>
    ''' 说明：模块名      
    ''' </summary>
    ''' <remarks></remarks>
    Private _nModuleName As String

    '    ''' <summary>
    '    ''' 说明：当前模块的权限     
    '    ''' </summary>
    '    ''' <remarks></remarks>
    '    Private _nModPowerModule As EditQx

    ''' <summary>
    ''' 说明：用户的模块权限记录集           
    ''' </summary>
    ''' <remarks></remarks>
    Private _nDtModPower As DataTable

    ''' <summary>
    ''' 中间库数据库连接信息
    ''' </summary>
    Private _nMidDbConnection1 As String

    Private _nErrMessage1 As String
    Private _nReportModFile1 As String
    Private _nDataSource1 As System.Data.DataSet
    Private _nOutPutDirectory1 As DirectoryInfo
    Private _nAppPath1 As String
    Private _nUserInfo1 As UserInfo
    Private _nModPowerModule As String
#End Region

#Region "类自定义参数及属性"


    ''' <summary>
    ''' 2019.11.19
    ''' 数据记录集dataset，默认包含(master,detail)等datatable
    ''' </summary>
    Public WriteOnly Property NDataSource As System.Data.DataSet
        Set
            _nDataSource1 = Value
        End Set
    End Property

    ''' <summary>
    ''' 说明：数据库链接字符串     
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NConnection As String
        Set(value As String)
            _nConnection1 = value
            Mdb.Connection = value
        End Set
    End Property

    ''' <summary>
    ''' 说明：字段模块名=f_columnlib.col_tablename       
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NColumnName As String
        Set(value As String)
            _nColumnName = value
        End Set
    End Property

    ''' <summary>
    ''' 说明：模块名     
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NModuleName As String
        Set(value As String)
            _nModuleName = value
        End Set
    End Property

    ''' <summary>
    ''' 应用实例id     
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NSysId As String
        Set(value As String)
            MSysID = value
        End Set
    End Property

    Public ReadOnly Property ModPowerReport As EditQx
        Get
            Return ""
        End Get
    End Property

    Public ReadOnly Property ShareNameList As String
        Get
            Return ""
        End Get
    End Property

    Public ReadOnly Property ControlNameList As String
        Get
            Return ""
        End Get
    End Property

    ''' <summary>
    ''' 说明：返回当前模块的用户权限      
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property ModPowerModule As EditQx
        Get
            Return _nModPowerModule
        End Get
    End Property

    ''' <summary>
    ''' 2019.2.13
    ''' 中间库数据库连接信息
    ''' </summary>
    Public WriteOnly Property NMidDbConnection As String
        Set
            _nMidDbConnection1 = Value
        End Set
    End Property
    ''' <summary>
    ''' 2019.7.3
    ''' 返回错误信息
    ''' </summary>
    ''' <returns></returns>
    Public ReadOnly Property NErrMessage As String
        Get
            Return _nErrMessage1
        End Get
    End Property
    ''' <summary>
    ''' 2019.7.3
    ''' 报表本地模块，路径
    ''' </summary>
    Public WriteOnly Property NReportModFile As String
        Set
            _nReportModFile1 = Value
        End Set
    End Property
    ''' <summary>
    ''' 2019.11.19
    ''' 报表导出文件夹目录
    ''' </summary>
    Public WriteOnly Property NOutPutDirectory As DirectoryInfo
        Set
            _nOutPutDirectory1 = Value
        End Set
    End Property
    ''' <summary>
    ''' 2020.5.4
    ''' 应用程序路径
    ''' </summary>
    Public WriteOnly Property NAppPath As String
        Set
            _nAppPath1 = Value
        End Set
    End Property
    ''' <summary>
    ''' 2021.5.22
    ''' 用户信息
    ''' </summary>
    Public WriteOnly Property NUserInfo As UserInfo
        Set
            _nUserInfo1 = Value
        End Set
    End Property
    Public WriteOnly Property NUserID As String
        Set
            MUser.UserId = Value
        End Set
    End Property
    Public WriteOnly Property NUserName As String
        set
            MUser.UserName = value
        End Set
    End Property 


    ''' <summary>
    ''' 2021.5.23
    ''' 报表类型，表格，图文
    ''' </summary>
    ''' <returns></returns>
    Public Property NTabType As String = "表格"
    ''' <summary>
    ''' 2023.2.28
    ''' 币种
    ''' </summary>
    Public Property NMoneyType As String = "RMB"

#End Region
#Region "类重构"

    '    ''' <summary>
    '    ''' 说明：重构  
    '    ''' </summary>
    '    ''' <param name="vUserName">用户名</param>
    '    ''' <param name="vSecuriKey">类授权代码</param>
    '    ''' <param name="vProcKey">过程及函数使用授权码</param>
    '    ''' <param name="vUserInfo">用户信息</param>
    '    ''' <param name="vIniPath">ini文件</param>
    '    ''' <param name="vPassKey">用户密码验证码</param>
    '    ''' <param name="vCheckCode">用户密码校验码</param>
    '    ''' <param name="vSqlitedb">sqlite数据库名</param>
    '    ''' <remarks></remarks>
    '    Public Sub New(ByVal vUserName As String, ByVal vSecuriKey As String, ByVal vProcKey As String,
    '                   ByVal vUserInfo As UserInfo, ByVal vIniPath As String, ByVal vPassKey As String,
    '                   ByVal vCheckCode As String, ByVal vSqlitedb As String)
    '        MyBase.New(vUserName, vSecuriKey, vProcKey)
    '        P_GetAssembleyName() '获取当前程序集信息
    '
    '        MUser = vUserInfo
    '        MUserSecurity.UserName = vUserName
    '        MUserSecurity.SecuriKey = vSecuriKey
    '        MUserSecurity.ProcKey = vProcKey
    '        CUserName = vUserName
    '        CSecuriKey = vSecuriKey
    '        CProcKey = vProcKey
    '        _nDtModPower = New DataTable()
    '        _nDtModPower.Clear()
    '        MClsConfig = New ConfigLib(MUserSecurity)
    '        MLog = New Loglib(CUserName, CSecuriKey, CProcKey, DbProviderType.SqlServer)
    '     '   Mini = New Ini(CUserName, CSecuriKey, CProcKey)
    '        '   MDbTab = New DataTabLib(CUserName, CSecuriKey, CProcKey)
    '
    '        MiniPath = vIniPath
    '        UPassKey = vPassKey
    '        UCheckCode = vCheckCode
    '        _nErrMessage1 = ""
    '    End Sub

    '    ''' <summary>
    '    ''' 类重构      
    '    ''' </summary>
    '    ''' <param name="vUserSecurity">用户验证信息，包含用户名，类验证码，类函数及事件授权码</param>
    '    ''' <param name="vUserInfo">用户信息</param>
    '    ''' <param name="vIniPath">ini文件</param>
    '    ''' <param name="vPassKey">用户密码验证码</param>
    '    ''' <param name="vCheckCode">用户密码校验码</param>
    '    ''' <param name="vSqlitedb">sqlite数据库名</param>
    '    ''' <remarks></remarks>
    '    Public Sub New(ByVal vUserSecurity As UserSecurity, ByVal vUserInfo As UserInfo, ByVal vIniPath As String,
    '                   ByVal vPassKey As String, ByVal vCheckCode As String, ByVal vSqlitedb As String)
    '        MyBase.New(vUserSecurity, vUserInfo)
    '        P_GetAssembleyName() '获取当前程序集信息
    '        MiniPath = vIniPath
    '        MUserSecurity = vUserSecurity
    '        CUserName = vUserSecurity.UserName
    '        CSecuriKey = vUserSecurity.SecuriKey
    '        CProcKey = vUserSecurity.ProcKey
    '        _nDtModPower = New DataTable()
    '        _nDtModPower.Clear()
    '        MUser = vUserInfo '用户信息
    '        MClsConfig = New ConfigLib(MUserSecurity)
    '        MLog = New Loglib(CUserName, CSecuriKey, CProcKey, DbProviderType.SqlServer)
    '        Mini = New Ini(CUserName, CSecuriKey, CProcKey)
    '        '   MDbTab = New DataTabLib(CUserName, CSecuriKey, CProcKey)
    '
    '
    '        UPassKey = vPassKey
    '        UCheckCode = vCheckCode
    '        _nErrMessage1 = ""
    '    End Sub

    ''' <summary>
    ''' 类重构      
    ''' </summary>
    ''' <param name="vUserInfo">用户信息</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal vUserInfo As UserInfo)

        '     P_GetAssembleyName() '获取当前程序集信息
        '    MiniPath = vIniPath
        _nDtModPower = New DataTable()
        _nDtModPower.Clear()
        MUser = vUserInfo '用户信息
        MClsConfig = New ConfigLib()
        '  MLog = New Loglib(CUserName, CSecuriKey, CProcKey, DbProviderType.SqlServer)
        'Mini = New Ini(CUserName, CSecuriKey, CProcKey)
        '   MDbTab = New DataTabLib(CUserName, CSecuriKey, CProcKey)

        _nErrMessage1 = ""
    End Sub

    ''' <summary>
    ''' 类重构      
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

        '     P_GetAssembleyName() '获取当前程序集信息
        '    MiniPath = vIniPath
        _nDtModPower = New DataTable()
        _nDtModPower.Clear()
        MClsConfig = New ConfigLib()
        '  MLog = New Loglib(CUserName, CSecuriKey, CProcKey, DbProviderType.SqlServer)
        'Mini = New Ini(CUserName, CSecuriKey, CProcKey)
        '   MDbTab = New DataTabLib(CUserName, CSecuriKey, CProcKey)

        _nErrMessage1 = ""
    End Sub
#End Region
    ''' <summary>
    ''' 2019年7月3日
    ''' 说明：用户权限模块提取       
    ''' </summary>
    ''' <param name="vUserName">用户名</param>
    ''' <param name="vModName">模块名，对应m_module.m_module</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetModPower(ByVal vUserName As String, ByVal vModName As String) As DataTable

        Dim dt As New DataTable
        Try


            MModPowerMReprt.ModPowerModule = EditQx.NoEdit
            MModPowerMReprt.ModPowerExportExcel = EditQx.NoEdit
            MModPowerMReprt.ModPowerReport = EditQx.NoEdit
            MModPowerMReprt.ControlNameList = ""
            MModPowerMReprt.ShareNameList = ""
            dt = MClsConfig.UserModulePower(vUserName, vModName, _nConnection1)
            If dt.Rows.Count > 0 Then
                For Each dr In dt.Rows
                    Select Case LCase(dr("PermissionCode").ToString)
                        Case LCase(vModName) + "_report"

                            MModPowerMReprt.ModPowerModule = CType(dr("QX").ToString, EditQx)
                            MModPowerMReprt.ShareNameList = dr("ShareName").ToString
                            MModPowerMReprt.ControlNameList = dr("ControlName").ToString
                        Case vModName + "_report" '2019.7.17
                            MModPowerMReprt.ModPowerReport = CType(dr("QX").ToString, EditQx)
                        Case Else

                            If LCase(vModName.Substring(Len(vModName) - 5, 5)) = "excel" Then '有控制excel报表
                                MModPowerMReprt.ModPowerExportExcel = CType(dr("QX").ToString, EditQx)
                            End If

                    End Select
                Next

            End If
        Catch ex As Exception
            'Loglib.WriteLog("log", "获取模块权限", "提取失败", "失败原因:" + ex.Message)
        End Try
        Return dt
    End Function

    ''' <summary>
    ''' 创建时间：2019.7.3
    ''' 说明：指定报表所在模块及报表id或者报表名，直接打开报表，其中包含2个DataTable,一个是ReportData保存报表清单；一个是RMDBMaster主查询记录集   
    ''' </summary>
    ''' <param name="vModName">报表所在的模块名，一般是f_report/m_id</param>
    ''' <param name="vDtMaster">主查询记录集</param>
    ''' <param name="vConnection">数据库链接字符串</param>
    ''' <returns>返回报表记录集</returns>
    ''' <remarks></remarks>
    Public Function DirectOpenReport(ByVal vModName As String, ByVal vConnection As String, ByVal vDtMaster As DataTable) As Integer

        Dim intsuc As Integer = -2
        Try
            '            '报表权限检查
            '            GetModPower(MUser.UserName, vModName)
            '            '   Return HideReportDlg(vRmReport, vWinForm, vDataSet, vModName, vRptName, vConnection, vDtMaster, Nothing, Nothing, Nothing)
            '            If MModPowerMReprt.ModPowerModule <> EditQx.EditAll Then
            '                Return -2
            '                Exit Function
            '            End If
            ShowDlg(_nReportModFile1, vDtMaster)
        Catch ex As Exception
            _nErrMessage1 = ex.Message
        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 创建时间：2019.10.20
    ''' 说明：指定报表所在模块及报表id或者报表名，直接打开报表，其中包含2个DataTable,一个是ReportData保存报表清单；一个是RMDBMaster主查询记录集   
    ''' </summary>
    ''' <param name="vModName">报表所在的模块名，一般是f_report/m_id</param>
    ''' <param name="vDataSource">数据记录集dataset，默认包含1个或者2个以上的datatable,其加载顺序是master,detail</param>
    ''' <param name="vConnection">数据库链接字符串</param>
    ''' <returns>返回报表记录集</returns>
    ''' <remarks></remarks>
    Public Function DirectOpenReport(ByVal vModName As String, ByVal vConnection As String, ByVal vDataSource As DataSet) As Integer

        Dim intsuc As Integer = -2
        Try
            '报表权限检查
            '            GetModPower(MUser.UserName, vModName)
            '            '   Return HideReportDlg(vRmReport, vWinForm, vDataSet, vModName, vRptName, vConnection, vDtMaster, Nothing, Nothing, Nothing)
            '            If MModPowerMReprt.ModPowerModule <> EditQx.EditAll Then
            '                Return -2
            '                Exit Function
            '            End If
            ShowDlg(_nReportModFile1, vDataSource)
        Catch ex As Exception
            _nErrMessage1 = ex.Message
        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 2019.11.19
    ''' 当前本地报表直接导出到本地，跳过预览环节
    ''' </summary>
    ''' <param name="vReportType">报表类型pdf,excel,word</param>
    ''' <param name="vReportModFile">报表模板,后缀名是*.rdlx</param>
    ''' <param name="vExportFilename">输出报表名</param>
    ''' <returns></returns>
    Public Function DirectExportReportToLocal(ByVal vReportType As MReportType, ByVal vReportModFile As String, ByVal vExportFilename As String) As Integer
        Dim intsuc As Integer = -2
        Try
            Select Case vReportType
                Case Is = 1 'excel
                    ReportExportExcel(vReportModFile, vExportFilename)
                Case Is = 3 'pdf
                    ReportExportPdf(vReportModFile, vExportFilename)
                Case Is = 2 'words
                    ReportExportWord(vReportModFile, vExportFilename)
            End Select
        Catch ex As Exception

        End Try
        Return intsuc
    End Function

    ''' <summary>
    ''' 2019.7.4
    ''' 调用报表
    ''' </summary>
    ''' <param name="vRptName"></param>
    ''' <param name="vMaindt">主查询记录集</param>
    ''' <returns></returns>
    Friend Function ShowDlg(ByVal vRptName As String, ByVal vMainDt As DataTable) As Integer
        Dim intsuc As Integer = -2
        Try
            Dim ds As New DataSet
            Dim obj As New DlgReportView
            With obj
                .NConnection = _nConnection1
                .NMidDbConnection = _nMidDbConnection1
                .NMainDataSource = vMainDt
                .NReportFileName = _nReportModFile1
                .WindowState = FormWindowState.Maximized
                MUser = _nUserInfo1 '2021.5.22 '用户信息
                .NDataSource = ds
                .LoadReport()
                .ShowDialog()

                .Close()
            End With
        Catch ex As Exception

        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 2019.10.20
    ''' 调用报表
    ''' </summary>
    ''' <param name="vRptName"></param>
    ''' <param name="vDataSource">数据集datast</param>
    ''' <returns></returns>
    Friend Function ShowDlg(ByVal vRptName As String, ByVal vDataSource As DataSet) As Integer
        Dim intsuc As Integer = -2
        Try
            Dim obj As New DlgReportView
            With obj
                .NConnection = _nConnection1
                .NMidDbConnection = _nMidDbConnection1
                ' .NMainDataSource =vMainDt
                .NDataSource = vDataSource '2019.10.20 加载记录集
                .NReportFileName = _nReportModFile1
                .WindowState = FormWindowState.Maximized
                MUser = _nUserInfo1 '2021.5.22 '用户信息
                .LoadReport()
                .ShowDialog()

                .Close()
            End With
        Catch ex As Exception

        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 2019.11.25
    ''' 直接调用报表清单对话框让用户自己选择
    ''' </summary>
    ''' <returns></returns>
    Public Function ShowReport() As Integer
        Dim intsuc As Integer = -2
        Try
            Dim obj As New DlgShowReport
            With obj
                .StartPosition = FormStartPosition.CenterParent
                .NModuleName = _nModuleName '模块名 f_report.m_byname
                .NConnection = _nConnection1
                .NMidDbConnection = _nMidDbConnection1
                .NDataSource = _nDataSource1
                .NMoneyType = NMoneyType '2023.2.28 '币种
                .NTabType = NTabType '2021.5.23
                MUser = _nUserInfo1 '2021.5.22 '用户信息
                .NAppPath = _nAppPath1 '2020.5.4应用程序路径
                .ShowDialog()
                .Close()
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return intsuc
    End Function
#Region "输出报表"

    ''' <summary>
    ''' 2019.11.19
    ''' 输出pdf
    ''' </summary>
    ''' <param name="vReportModFile">报表模板，后缀名是*.rdlx文件</param>
    ''' <param name="vExportFileName">输出报表名</param>
    ''' <returns></returns>
    Private Function ReportExportPdf(ByVal vReportModFile As String, ByVal vExportFilename As String) As Integer
        Dim intsuc As Integer = -2
        Try
            Dim report As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(vReportModFile))
            Dim reportDocument As GrapeCity.ActiveReports.Document.PageDocument = New GrapeCity.ActiveReports.Document.PageDocument(report)
            AddHandler reportDocument.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件，进行事件加载
            Dim pdfRenderingExtension As GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension = New PdfRenderingExtension()
            Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(_nOutPutDirectory1, System.IO.Path.GetFileNameWithoutExtension(vExportFilename))
            outputProvider.OverwriteOutputFile = True
            reportDocument.Render(pdfRenderingExtension, outputProvider)
            intsuc = 1
        Catch ex As Exception
            MsgBox("输出报表失败，失败原因" + ex.Message, , "错误")
        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 2019.11.19
    ''' 输出excel
    ''' </summary>
    ''' <param name="vReportModFile">报表模板,后缀名是*.rdlx</param>
    ''' <param name="vExportFileName">输出报表名</param>
    ''' <returns></returns>
    Private Function ReportExportExcel(ByVal vReportModFile As String, ByVal vExportFilename As String) As Integer
        Dim intsuc As Integer = -2
        Try

            Dim report As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(vReportModFile))
            Dim reportDocument As GrapeCity.ActiveReports.Document.PageDocument = New GrapeCity.ActiveReports.Document.PageDocument(report)
            AddHandler reportDocument.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件，进行事件加载
            Dim excelSetting As GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings = New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings()
            excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx
            excelSetting.MultiSheet = False '多页面时，不分开，还是在excel一个sheet显示
            Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = excelSetting
            Dim excelRenderingExtension As GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension = New GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension()
            Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(_nOutPutDirectory1, System.IO.Path.GetFileNameWithoutExtension(vExportFilename))
            outputProvider.OverwriteOutputFile = True
            reportDocument.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings())
            intsuc = 1
        Catch ex As Exception
            MsgBox("报表输出错误,错误原因" + ex.Message, , "错误")
        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 2019.11.18
    ''' 输出excel
    ''' </summary>
    ''' <param name="vReportModFile">报表模板,后缀名是*.rdlx</param>
    ''' <param name="vExportFileName">输出报表名</param>
    ''' <returns></returns>
    Private Function ReportExportWord(ByVal vReportModFile As String, ByVal vExportFilename As String) As Integer
        Dim intsuc As Integer = -2
        Try

            Dim report As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(vReportModFile))
            Dim reportDocument As GrapeCity.ActiveReports.Document.PageDocument = New GrapeCity.ActiveReports.Document.PageDocument(report)
            AddHandler reportDocument.LocateDataSource, AddressOf OnLocateDataSource '添加动态数据源事件，进行事件加载
            Dim wordSetting As GrapeCity.ActiveReports.Export.Word.Page.Settings = New GrapeCity.ActiveReports.Export.Word.Page.Settings()
            wordSetting.FileFormat = GrapeCity.ActiveReports.Export.Word.Page.FileFormat.OOXML
            Dim setting As GrapeCity.ActiveReports.Extensibility.Rendering.ISettings = wordSetting
            Dim wordRenderingExtension As GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension = New GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension()
            Dim outputProvider As GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(_nOutPutDirectory1, System.IO.Path.GetFileNameWithoutExtension(vExportFilename))
            outputProvider.OverwriteOutputFile = True
            reportDocument.Render(wordRenderingExtension, outputProvider, wordSetting)

            intsuc = 1
        Catch ex As Exception
            MsgBox("报表输出错误,错误原因" + ex.Message, , "错误")
        End Try
        Return intsuc
    End Function
    ''' <summary>
    ''' 2019.7.4
    ''' 数据源加载程序
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="args"></param>
    Private Sub OnLocateDataSource(ByVal sender As Object, ByVal args As GrapeCity.ActiveReports.LocateDataSourceEventArgs)


        If _nDataSource1.Tables.Count = 1 Then

            If LCase(Convert.ToString(args.DataSet.Name)) = "master" Then
                args.Data = _nDataSource1.Tables(0)
            End If
            If LCase(Convert.ToString(args.DataSet.Name)) = "detail" Then
                args.Data = _nDataSource1.Tables(1)
            End If
        ElseIf _nDataSource1.Tables.Count = 2 Then
            If LCase(Convert.ToString(args.DataSet.Name)) = "master" Then
                args.Data = _nDataSource1.Tables(0)
            End If
            If LCase(Convert.ToString(args.DataSet.Name)) = "detail" Then 'Detail
                args.Data = _nDataSource1.Tables(1)
            End If
        End If


    End Sub

#End Region
End Class

